package com.zhuge_new.Activity;

import android.app.Activity;
import android.arch.lifecycle.ViewModelProvider;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.zhuge_new.Adapter.DataileAdapter;
import com.zhuge_new.Adapter.RedMoneyimgAdapter;
import com.zhuge_new.Adapter.RedheadAdapter;
import com.zhuge_new.Base.BaseActivity;
import com.zhuge_new.R;
import com.zhuge_new.bean.RedDisolayBean;
import com.zhuge_new.http.StringDialogCallback;
import com.zhuge_new.share.BaseHttp;
import com.zhuge_new.untils.ActivityStack;
import com.zhuge_new.untils.DataParse;
import com.zhuge_new.untils.StatusBarUtil;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by lenovo on 2018-09-20.
 */

public class DetaileActivity extends Activity implements View.OnClickListener {
    private Activity baseContext;
    private View view;
    private RedDisolayBean redDisolayBean;
    private String redpacketId;
    private RecyclerView detaie_list;
    private ImageView detaie_logo;
    private TextView detaie_name;
    private TextView detaie_money;
    private TextView detaie_grade;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detaie);
        baseContext=this;
        view = View.inflate(baseContext, R.layout.detaie_head,null);
        Intent intent=getIntent();
        redpacketId = intent.getStringExtra("redpacketId");
        init_title();
        gettoolr();
        getdata();
    }

    public void init_title() {
        detaie_list = findViewById(R.id.detaie_list);
        ImageView detaie_back=view.findViewById(R.id.detaie_back);
        detaie_logo = view.findViewById(R.id.detaie_logo);
        detaie_name = view.findViewById(R.id.detaie_name);
        detaie_money = view.findViewById(R.id.detaie_money);
        detaie_grade = view.findViewById(R.id.detaie_grade);
        detaie_back.setOnClickListener(this);
        detaie_list.setLayoutManager(new LinearLayoutManager(this));
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.detaie_back:
                ActivityStack.getScreenManager().popOneActivity(DetaileActivity.class);
                break;
        }
    }

    public void getdata() {
        Log.e(redpacketId,"打印数据id" );
            OkGo.<String>post(BaseHttp.selInfoByRedpacketId)
                    .params("redpacketId", redpacketId)
                    .execute(new StringDialogCallback(baseContext) {
                        @Override
                        public void onSuccessResponse(Response<String> response, String msg, String msgCode) {
                            redDisolayBean = (RedDisolayBean) new DataParse().getBean(response.body(), RedDisolayBean.class, 0);
                            Glide.with(baseContext).load(redDisolayBean.getObject().getThreeHeadPhoto()).into(detaie_logo);
                            detaie_name.setText(redDisolayBean.getObject().getThreeNickName());
                            detaie_money.setText(redDisolayBean.getObject().getMoney());
                            detaie_grade.setText("领取"+redDisolayBean.getObject().getSum()+"/"+redDisolayBean.getObject().getNum());
                            DataileAdapter dataileAdapter=new DataileAdapter(baseContext,redDisolayBean);
                            dataileAdapter.addHeaderView(view);
                            dataileAdapter.setHeaderFooterEmpty(true, true);
                            detaie_list.setAdapter(dataileAdapter);
                        }
                    });
    }

    public void gettoolr() {
        StatusBarUtil.setStatusBarColor(this,R.color.red_red);
    }
}
